package com.example.covid19.FaceUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.example.covid19.common.lang.Result;
import com.example.covid19.util.Face;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.HashMap;

import static com.example.covid19.util.Face.getBytesFromFile;
import static com.example.covid19.util.Face.post;

@RestController
@RequestMapping("/reg")
@Slf4j
public class FaceReg {
    @Autowired
    Face face;
    @Autowired
    FaceMe faceMe;
    /***
     * 识别token
     */
    @RequestMapping("/add")
    public Result face() throws Exception {
        String url = " https://api-cn.faceplusplus.com/facepp/v3/faceset/removeface";
        HashMap<String, String> map = new HashMap<>();
        HashMap<String, byte[]> byteMap = new HashMap<>();
        map.put("api_key", "puaPEqTKRAATMQu35U8y3SwQGiLJduX0");
        map.put("api_secret", "vXTB_SEI0P3sZg3UPcJym7bxb6MrAW8p");
        map.put("faceset_token","285714627291c5130a4840badca617e2");
        map.put("face_tokens","fa8c66367e074e9360a543d29eff47f0");
        map.put("return_landmark", "1");
        map.put("return_attributes", "gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus");
        byte[] bacd = post(url, map, byteMap);
        String str = new String(bacd);
        JSONObject object = JSONUtil.parseObj(str);
        System.out.println(object);
        String str3 = object.getStr("faces");
        System.out.println(str);
        return Result.success(200,"识别成功",str);
    }


}

